using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class UICraftList : MonoBehaviour
{
    [SerializeField] private Transform craftSoltParent;
    [SerializeField] private GameObject craftSlotPrefab;
    [SerializeField] private List<EquipItemData> craftEquipmentList;
    [SerializeField] private List<UICraftSolt> craftSoltList; 
    private void Start()
    {
        AssingCraftSolt();
        SetupCraftList();
    }
    private void AssingCraftSolt()
    {
        for (int i = 0; i < craftSoltParent.childCount; i++)
        {
            craftSoltList.Add(craftSoltParent.GetChild(i).GetComponent<UICraftSolt>());
        }
    }
    public void SetupCraftList()
    {
        for (int i = 0; i < craftSoltList.Count; i++)
        {
            Destroy(craftSoltList[i].gameObject);
        }
        craftSoltList = new List<UICraftSolt>();
        for (int i = 0; i < craftEquipmentList.Count; i++)
        {
            GameObject newSlot = Instantiate(craftSlotPrefab, craftSoltParent);
            newSlot.GetComponent<UICraftSolt>().Setup(craftEquipmentList[i]);
            craftSoltList.Add(newSlot.GetComponent<UICraftSolt>());
        }
    } 
}
